package com.itheima.web.servlet; /**
 * @author Xiao
 * @date 2021/9/8
 */

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.Brand;
import com.itheima.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/sellectAllServlet")
public class SellectAllServlet extends HttpServlet {
    private final BrandServiceImpl brandService = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Brand> list = brandService.selectAll();
        String brands = JSON.toJSONString(list);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(brands);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
